﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace WindowsService1
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            WriteLog("启动："+TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now).ToString());
            this.timer1.Start();
            while (true)
            {
                WriteLog("while："+ DateTime.Now);
                try
                {
                    ServiceReference1.WebService1SoapClient s = new ServiceReference1.WebService1SoapClient();
                    s.AppentStr2TxtAsync(TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now).ToString());
                }
                catch (Exception ex)
                {
                    WriteLog(ex.Message);
                }
                System.Threading.Thread.Sleep(1000*60);
            }
            
        }

        protected override void OnStop()
        {
            WriteLog("停止：" + TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now).ToString());
        }

        public void WriteLog(string str)
        {
            using (StreamWriter sw = File.AppendText(@"d:\黄宏光题目4测试服务运行日志信息.txt"))
            {
                sw.WriteLine(str);
                sw.Flush();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           
        }
    }
}
